//! Copyright 2012 Virtium Technology, Inc.
//! All rights reserved
//!
#ifndef __Rtc_h__
#define __Rtc_h__

#include "BasicTypes.h"

#if defined (__FW_BUILD__)
extern "C" {
    extern volatile U8 s_UpdateTimeFlag;
    extern void SysTick_Handler(void);
}
#endif


class cRtc
{
public:
    static const U8 STR_TIME_LENGTH = 6;

    typedef struct
    {
        U8 m_year;
        U8 m_month;
        U8 m_date;
        U8 m_hour;
        U8 m_minute;
        U8 m_second;
    }st_StrTime;

private:
    #if !defined (__FW_BUILD__)
        static volatile U8 s_UpdateTimeFlag;
    #endif
        static U32 s_RtcCount;
        static st_StrTime s_RtcStr;
private:
    static void Configuration();
    static void TimeAdjust(U32 iTimeCount);
    static void DisableTamper();
    static bool IsLeapYear(U16 iYear);
    static U8   DayOfWeek(U16 CurrentYear,U8 CurrentMonth,U8 CurrentDay);
    static U32  TotalDate(st_StrTime *strTime);
    static U32  StrToTime(st_StrTime *strTime);
    static st_StrTime IntToTime(U32 time_cnt);
    static void IncDate(st_StrTime *time);
    static void UpdateTime();


public:
    static void InitReset();
    static inline U8* GetTimeAsStr()
    {
        return ( (U8*)(&s_RtcStr) );
    }
    static bool SetTimeAsStr(U8* pStrTime);
    static void RunOne();
};

#endif // __Rtc_h__
